package codeine;

import java.util.Map;

import javax.inject.Inject;

import codeine.jsons.project.ProjectJson;
import codeine.jsons.project_status.ProjectStatus;
import codeine.jsons.project_status.ProjectStatusList;

import com.google.common.collect.Maps;

public class ProjectStatusUpdater {

	@Inject private ProjectStatusList projectStatusList;

	public String updateStatus(ProjectJson project, String monitor, String result, String node) {
		Map<String, String> map = initStatus(project, node);
		String $ = map.get(monitor);
		map.put(monitor, result);
		return $;
	}

	public Map<String, String> initStatus(ProjectJson project, String node) {
		ProjectStatus projectStatus = projectStatusList.project_name_to_status.get(project.name());
		if (null == projectStatus){
			projectStatus = new ProjectStatus();
			projectStatusList.project_name_to_status.put(project.name(), projectStatus);
		}
		Map<String, String> map = projectStatus.monitor_to_status().get(node);
		if (null == map){
			map = Maps.newHashMap();
			projectStatus.putIn_monitor_to_status(node, map);
		}
		return map;
	}
}
